package mall.kotlin.com.myapplication.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import mall.kotlin.com.myapplication.R;

/**
 * USER: zjw
 * DATA: 2018/11/14 0014
 * TIME: 下午 2:26
 */
public class TitleHeader extends RelativeLayout {
    RelativeLayout mRelativeLayout;
    private ImageView mLeft;
    private ImageView mRight;
    private TextView mTvTitle;
    private int mBgColor;
    private int mTitleColor;
    private String mName;

    public TitleHeader(Context context) {
        super(context);
        init(context);
    }

    public TitleHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleHeader);
        mBgColor = typedArray.getColor(R.styleable.TitleHeader_root_bg, 0xfffff00);
        mTitleColor = typedArray.getColor(R.styleable.TitleHeader_title_color, 0xfffff00);
        mName = typedArray.getString(R.styleable.TitleHeader_title_size);
        typedArray.recycle();
        init(context);
    }

    public TitleHeader(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        mRelativeLayout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.header_title, this, true);
        mLeft = mRelativeLayout.findViewById(R.id.left);
        mRight = mRelativeLayout.findViewById(R.id.right);
        mTvTitle = mRelativeLayout.findViewById(R.id.text_title);
        mRelativeLayout.setBackgroundColor(mBgColor);
        mTvTitle.setTextColor(mTitleColor);
        mTvTitle.setText(mName);
    }

    public void setLeftOnclick(OnClickListener leftOnclick) {
        if (mLeft != null && leftOnclick != null) {
            mLeft.setOnClickListener(leftOnclick);
        }
    }
    public void setRihtOnclick(OnClickListener leftOnclick) {
        if (mRight != null && leftOnclick != null) {
            mRight.setOnClickListener(leftOnclick);
        }
    }

}
